package com.maiji.cloud.utils;

import com.alibaba.fastjson.JSONObject;

import java.io.BufferedReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;

public class JsonUtil {

    public static String getBodyString(BufferedReader br) {
        String inputLine;
        String str = "";
        try {
            while ((inputLine = br.readLine()) != null){

                str += inputLine;
            }
            br.close();
        } catch (IOException e) {
            System.out.println("IOException: " + e);
        }
        return str;
    }

    public static HashMap<String, Object> jsonStrToHashMap(String text)
    {
        HashMap<String, Object> data = new HashMap();
        // 将json字符串转换成jsonObject
        JSONObject jsonObject = JSONObject.parseObject(text);
        Set<String> keySet = jsonObject.keySet();

        // 遍历jsonObject数据，添加到Map对象
        for(String key : keySet){
            Object value =  (Object)jsonObject.get(key);
            data.put(key, value);
        }

        return data;
    }


}
